#ifndef DISPATCHER_H
#define DISPATCHER_H
#include <memory>
#include "opencv2/opencv.hpp"
#include "configuration.h"
#include "posenet.h"
#include "Ctracker.h"
#include "mtcnn.h"
#include "genderpredictor.hpp"
#include "FaceRecognizer.h"
#include "statistics.h"
#include "common.h"
#include "render.h"
#include "ssddetector.hpp"
#include "videostream.h"

class Dispatcher
{
	using face_detect = std::pair<std::pair<cv::Mat, cv::Rect>, std::vector<cv::Point2f>>;
	using track_info = std::map<int, std::vector<std::pair<cv::Point, bool>>>;
	using second_type = std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>;
public:
	void load_params(const string& config_file);
	void run();

protected:
	void init_modules();
	void update_face_info(cv::Mat frame);
	face_detect get_face(cv::Mat frame, const cv::Rect& detect_region) const;

	std::vector<Track_Info> convert_tracker_to_render()const;
	std::vector<std::pair<cv::Point, bool>> convert_track_to_pointsvec(const CTrack* track)const;
	void update_infos(const std::vector<Track_Info>& infos);
private:
	void update_det_tracker(cv::Mat frame);

protected:
	Parameters mParams;
	//std::unique_ptr<Posenet> m_pose_net;
	std::shared_ptr<CTracker> m_tracker;
	std::unique_ptr<mtcnn> m_face_detector;
	std::unique_ptr<FaceInfo::GenderAge> m_gender;
	std::unique_ptr<fr::FaceRecognizer> m_face_id;
	std::unique_ptr<PersonDetector> m_detector;

	//source
	std::unique_ptr<VideoStream> m_videostream;

	//statitics
	std::unique_ptr<Statistics> m_statistics;
	//bool partial_render = true;

	//render
	std::unique_ptr<Render> m_render;
};

#endif // !DISPATCHER_H

